package cn.com.darly.vpm.business.friend.impl;


import cn.com.darly.vpm.business.friend.bean.FriendShip;
import cn.com.darly.vpm.business.friend.bean.FriendShipExample;
import cn.com.darly.vpm.business.friend.dao.FriendShipMapper;
import cn.com.darly.vpm.business.friend.service.FriendShipService;
import cn.com.darly.vpm.framework.base.AbstractBaseService;
import cn.com.darly.vpm.framework.base.BaseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author : ZhangYuHui
 * Date : 2018/4/20
 * TODO :
 */
@Service
public class FriendShipServiceImplementer extends AbstractBaseService<FriendShip,FriendShipExample> implements FriendShipService {

    @Autowired
    FriendShipMapper shipMapper;

    @Override
    public List<FriendShip> findFriendByUserID(String userid) {
        FriendShipExample search = new FriendShipExample();
        search.createCriteria().andUseridEqualTo(userid).andFriendupNotEqualTo("0");
        return shipMapper.selectByExample(search);
    }

    @Override
    public FriendShip isFriend(String userid, String friendid) {
        FriendShipExample search = new FriendShipExample();
        search.createCriteria().andUseridEqualTo(userid).andFriendidEqualTo(friendid);
        List<FriendShip> friendShips = shipMapper.selectByExample(search);
        if (friendShips!=null&&friendShips.size()>0){
            return friendShips.get(0);
        }else {
            return null;
        }
    }

    @Override
    public List<FriendShip> getListByLoginUserId(String id) {
        FriendShipExample search = new FriendShipExample();
        search.createCriteria().andFriendidEqualTo(id).andFriendupEqualTo("0");
        return  shipMapper.selectByExample(search);
    }

    @Override
    public List<FriendShip> getListByFriendId(String id) {
        FriendShipExample search = new FriendShipExample();
        search.createCriteria().andUseridEqualTo(id).andFriendupEqualTo("0");
        return  shipMapper.selectByExample(search);
    }

    @Override
    protected BaseMapper<FriendShip, FriendShipExample> getBaseMapper() {
        return shipMapper;
    }
}
